package panel;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

/**
 * Default Lemon-Grass themed row-striped table to display a file-listing. Double-clicking
 * any row launches the respective file.
 * 
 * TODO
 * 		1) Allow file-renaming when the name column is double-clicked
 * 		2) Allow adding of tags, when the tags column is double-clicked
 * 		3) Launch file only when icon column is double-clicked
 * 
 * @author Shahriar Haque
 *
 */
public class Snowtable extends JTable {

	private static final long serialVersionUID = 1L;
	
	
	public Snowtable(DefaultTableModel t) { 
		super(t);
		
		this.showVerticalLines = false;
		this.showHorizontalLines = false;
		setFont(new Font("Tahoma",0,12));
		
		
		JTableHeader header = this.getTableHeader();
		header.setDefaultRenderer(new CustomTableHeaderRenderer());
	}
	
	public Component prepareRenderer(TableCellRenderer renderer,int Index_row, int Index_col) {
		Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
		
		
		//even index, selected or not selected
		if (Index_row % 2 == 0 ) {
			comp.setBackground(new Color(222,231,212));
		}
		
		else {
			comp.setBackground(new Color(240,243,234));
		}
		
		// highlights the selected row blue
		if(isCellSelected(Index_row, Index_col)){
			comp.setForeground(Color.white);
			comp.setBackground(new Color(98,140,175));
		}
		
		
		else{
			comp.setForeground(Color.black);
		}
		return comp;
	}

	public boolean isCellEditable(int rowIndex, int colIndex) {
        return false;   //Disable editing of any cell
      }
}
